let ul = document.querySelector('#main ul')
let ol = document.querySelector('#main ol')

function getUrlParams() {
    let url = location.href;
    let regExp = /.*\?([^\?]+)/
    let query = {}; //最终处理好的参数
    let search = regExp.exec(url);
    //productid=23&NAME=123"
    // console.log(search);
    search = search[1];
    //有没有多个query参数,有的话肯定以&进行连接
    let searchArr = [];
    if (search.indexOf("&")) {
        searchArr = search.split("&")
    } else {
        search = search.split()
    }

    searchArr.forEach(item => {
        let queryArr = item.split("=");
        query[queryArr[0]] = queryArr[1]
    })

    return query
}

let query = getUrlParams();


console.log(query.productid);
let productid = query.productid

$.ajax({
    // url: `http://chst.vip:8081/mmb/bijia.html?title=${title}&categoryid=${categoryid}`,
    url: ` http://chst.vip:1234/api/getproduct?productid=${productid}`,

}).then(res => {
    console.log(res.result);
    let html = '';
    res.result.forEach(item => {
        html += `
            <li productid=${item.productId}>
            ${item.productImg}<br><span>
            ${item.productName}</span>
            <span>${item.bjShop}</span
            `
    })
    ul.innerHTML = html;

})
$.ajax({
    // url: `http://chst.vip:8081/mmb/bijia.html?title=${title}&categoryid=${categoryid}`,
    url: ` http://chst.vip:1234/api/getproductcom?productid=${productid}`,

}).then(res => {
    console.log(res.result);
    let html = '';
    res.result.forEach(item => {
        html += `
            <li comid=${item.comId}>
            <span>${item.comName}</span><span>${item.comTime}</span><br><span>${item.comContent}</span>
            <p>${item.comFrom}</p>
            `
    })
    ol.innerHTML = html;

})